package com.ai.zhly.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.common.bean.CommonBaseBean;
import com.ai.dmc.index.common.bean.StaffSessBean;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;
import com.ai.zhly.util.DBSequence;
import com.mysql.fabric.xmlrpc.base.Data;
/**
 * 
* @Title: MapDataImpl.java
* @Description: 家装宽带展示层service
* @author xueyf3  
* @date 2016年5月23日 下午4:22:54
* Copyright：Copyright (c) 2016
* Company：北京亚信智慧数据科技有限公司
* @version V1.0
 */
public class LoginServiceImpl extends BaseServiceImpl implements ILoginService{
	// 定义对应Mapper文件的命名空间
    private static final String NAMESPACE = "Login.";
    
    public static Logger log = LoggerFactory.getServiceLog(LoginServiceImpl.class);
    
	@Override
	public void queryUserByIdAndPwd(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		

		String userId = inputObject.getParams().get("userId");
		userId = userId.toUpperCase();
		inputObject.getParams().put("userId", userId);
		StaffSessBean sessionBean = null;
		sessionBean = this.getBaseDao().queryForObject(
                NAMESPACE + "queryLoginUserInfo", inputObject.getParams(),StaffSessBean.class);
		if (null != sessionBean) {
			// 验证用户角色
			List<StaffSessBean> sList = this.getBaseDao().queryForList(NAMESPACE+"queryLoginUserJob", inputObject.getParams(),StaffSessBean.class);
			String jobId = "";
			String jobName = "";
			if (null != sList && sList.size() > 0) {
				for (StaffSessBean s : sList) {
					jobId += s.getJobId() + ";";
					jobName += s.getJobName() + ";";
				}
			}
			sessionBean.setJobId(jobId);
			sessionBean.setJobName(jobName);
			
			//登陆成功插入记录表
			//判断用户是否存在
			StaffSessBean com=this.getBaseDao().queryForObject(NAMESPACE+"validUser",inputObject.getParams(), StaffSessBean.class);
			if(null !=com){
				Map<String,String> map=new HashMap<String,String>();
				String LOG_ID=DBSequence.getInstance().getSequence();
				map.put("LOG_ID", LOG_ID);
				map.put("LOG_CONTENT", "登陆");
				map.put("USER_ID",userId);
				map.put("USER_NAME",com.getUserName());
				map.put("USER_IP","");
				map.put("USER_MAC","");
				map.put("LOG_TIME",new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString());
				map.put("FUNC_ID","loginIn");
				this.getBaseDao().insert(NAMESPACE+"loginIn",map);
			}
			
		}
		
		outputObject.setObject(sessionBean);
		


		// 记录登录日志
//		String logContent = "登录";
//		String funcId = "loginIn";
//		LogDSUtil logDSUtil = new LogDSUtil();
//		LogDSUtil.insertVisitLog(sessionBean, logContent, funcId);
//
//		loginInfo.put("loginCode", "0");
//		loginInfo.put("loginDesc", "登录成功");
//		RequestParameterUtil.encodeHttpServletRequest(httpServletResponse);
//		httpServletResponse.getWriter().write(loginInfo.toString());

		
	}
	

}
